package com.xjtu.project.controller.admin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.xjtu.project.common.utls.JsonResponse;
import com.xjtu.project.model.domain.Employee;
import com.xjtu.project.model.domain.Size;
import com.xjtu.project.model.dto.EmployeeDTO;
import com.xjtu.project.service.EmployeeService;
import com.xjtu.project.service.SizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    @GetMapping("employee/page")
    public JsonResponse getEmployeePage(EmployeeDTO emp) {
        Page<Employee> lists  = employeeService.selectPagedMy(emp);
        return JsonResponse.success(lists);
    }

    @PostMapping("employee/login")
    public JsonResponse login(@RequestBody Employee emp){
        Employee login = employeeService.login(emp);
        return JsonResponse.success(login);
    }

    @PostMapping("employee")
    public JsonResponse addEmployee(@RequestBody Employee emp){
        Integer addEmp = employeeService.addEmployee(emp);
        return JsonResponse.success(addEmp);
    }

    @GetMapping("employee/{id}")
    public JsonResponse getEmployee(@PathVariable("id") Integer id){
        Employee emp = employeeService.getById(id);
        return JsonResponse.success(emp);
    }

    @PutMapping("employee")
    public JsonResponse updateEmployee(@RequestBody Employee emp){
        boolean b = employeeService.updateByMy(emp);
        return JsonResponse.success(b);
    }
}
